package com.imooc.utils;

import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;

public class MD5Utils {

	/**
	 * 
	 * @Title: MD5Utils.java
	 * @Package com.imooc.utils
	 * @Description: 对字符串进行md5加密
	 */
	public static String getMD5Str(String data) throws Exception {
		try {
			MessageDigest md =
					MessageDigest.getInstance("MD5");
			byte[] array = md.digest(data.getBytes(StandardCharsets.UTF_8));
			StringBuilder sb = new StringBuilder();
			for (byte item : array) {
				sb.append(Integer.toHexString((item & 0xFF) |
						0x100).substring(1, 3));
			}
			return sb.toString().toUpperCase();
		} catch (Exception exception) {
		}
		return null;
	}

	public static void main(String[] args) {
		try {
			String md5 = getMD5Str("abc");
			System.out.println(md5);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
